//
//  CYTicketDetailMiddleView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/8/18.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYTicketDetailMiddleView.h"
@interface CYTicketDetailMiddleView()
@property (nonatomic, strong) CYLabel *money_titleLBL;//
@property (nonatomic, strong) CYLabel *peopleNum_titleLBL;//
@property (nonatomic, strong) CYLabel *moneyLBL;//销量
@property (nonatomic, strong) CYLabel *peopleNumLBL;//人数
@property (nonatomic, strong) CYView *topLine;//
@property (nonatomic, strong) CYView *midLine;
@property (nonatomic, strong) CYView *bottomLine;
@end
@implementation CYTicketDetailMiddleView
- (instancetype)initWithColor:(UIColor *)color{
    self = [super initWithColor:color];
    if (self) {
        self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, 10 * 2 + AUTO(30) * 2);
        self.topLine.hidden = self.midLine.hidden = self.bottomLine.hidden = NO;
        self.money_titleLBL.hidden = self.moneyLBL.hidden = self.peopleNum_titleLBL.hidden = self.peopleNumLBL.hidden = NO;
    }
    return self;
}

- (CYLabel *)money_titleLBL{
    if (!_money_titleLBL) {
        _money_titleLBL = [[CYLabel alloc]initWithText:@"本期销量:" size:12 textcolor:ColorHex(0x333333)];
        [self addSubview:_money_titleLBL];
        
        
        [_money_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).with.offset(- (self.bounds.size.height - 10 * 2) / 4.0);
            make.left.equalTo(self).with.offset(10);
            make.size.mas_equalTo(_money_titleLBL.bounds.size);
        }];
    }
    return _money_titleLBL;
}

- (CYLabel *)peopleNum_titleLBL{
    if (!_peopleNum_titleLBL) {
        _peopleNum_titleLBL = [[CYLabel alloc]initWithText:@"参与人数:" size:12 textcolor:ColorHex(0x333333)];
        [self addSubview:_peopleNum_titleLBL];
        
        [_peopleNum_titleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).with.offset((self.bounds.size.height - 10 * 2) / 4.0);
            make.left.equalTo(_money_titleLBL);
            make.size.mas_equalTo(_peopleNum_titleLBL.bounds.size);
        }];
    }
    return _peopleNum_titleLBL;
}

- (CYLabel *)moneyLBL{
    if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:@"元" size:12 textcolor:ColorHex(0x888888)];
        _moneyLBL.textAlignment = NSTextAlignmentRight;
        [self addSubview:_moneyLBL];
        
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.mas_right).with.offset(- 10);
            make.left.equalTo(_money_titleLBL.mas_right).with.offset(5);
            make.centerY.equalTo(_money_titleLBL);
            make.height.mas_equalTo(_moneyLBL.bounds.size.height);
        }];
    }
    return _moneyLBL;
}

- (CYLabel *)peopleNumLBL{
    if (!_peopleNumLBL) {
        _peopleNumLBL = [[CYLabel alloc]initWithText:@"人" size:12 textcolor:ColorHex(0x888888)];
        _peopleNumLBL.textAlignment = NSTextAlignmentRight;
        [self addSubview:_peopleNumLBL];
        
        [_peopleNumLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_moneyLBL);
            make.left.equalTo(_moneyLBL);
            make.centerY.equalTo(_peopleNum_titleLBL);
            make.height.mas_equalTo(_peopleNumLBL.bounds.size.height);
        }];
    }
    return _peopleNumLBL;
}

- (CYView *)topLine{
    if (!_topLine) {
        _topLine = [[CYView alloc]initWithColor:ColorHex(0xf5f5f9)];
        _topLine.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, 10);
        [self addSubview:_topLine];
        
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(0);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(_topLine.bounds.size);
        }];
    }
    return _topLine;
}

- (CYView *)midLine{
    if (!_midLine) {
        _midLine = [[CYView alloc]initWithColor:ColorHex(0xf5f5f9)];
        [self addSubview:_midLine];
        
        [_midLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 10 * 2, 0.5));
        }];
    }
    return _midLine;
}


- (CYView *)bottomLine{
    if (!_bottomLine) {
        _bottomLine = [[CYView alloc]initWithColor:ColorHex(0xf5f5f9)];
        [self addSubview:_bottomLine];
        
        [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).with.offset(0);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(_topLine.bounds.size);
        }];
    }
    return _bottomLine;
}

- (void)setPeopleNum:(NSString *)peopleNum{
    if (_peopleNum != peopleNum)
        _peopleNum = peopleNum;
    self.peopleNumLBL.attributedText = [self AttributedString:[NSString stringWithFormat:@"%@人",peopleNum]];
}

- (void)setMoney:(NSString *)money{
    if (_money != money)
        _money = money;
    self.moneyLBL.attributedText = [self AttributedString:[NSString stringWithFormat:@"%@元", money]];
    
}

- (NSMutableAttributedString *)AttributedString:(NSString *)string{
    
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:string];
    UIFont *font = [UIFont systemFontOfSize:12];
    [attributeStr addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)];
    [attributeStr addAttribute:NSForegroundColorAttributeName value:THEME_COLOR range:NSMakeRange(0, string.length - 1)];
    return attributeStr;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
